using System.Collections.Generic;
using System.Data;
using Magiq.Behaviors;
using Magiq.Delete;

namespace Magiq.Databases.Delete
{
    public class DatabaseDeleteBehavior<T> : DefaultBehavior, IDatabaseDeleteBehavior<T> where T : class
    {
        private IOrmAdapter ormAdapter;
        private IDelete<T> delete;

        #region IDatabaseDeleteBehavior<T> Members

        public void Initialize(IOrmAdapter ormAdapter, IDelete<T> delete)
        {
            this.ormAdapter = ormAdapter;
            this.delete = delete;
        }

        public IDbCommand BuildCommand(DatabaseDelete<T> databaseDelete)
        {
            var builder = new DeleteCommandBuilder(databaseDelete.OrmAdapter, databaseDelete.Source);
            return builder.GetCommand();
        }

        public IEnumerable<DatabaseDelete<T>> BuildDatabaseDeletes()
        {
            return ormAdapter.BuildDatabaseDeletes(delete);
        }

        #endregion
    }
}